//================v3要点总结===============
/**
 * v2的优化版，将空间复杂度从O(n) 变为O(1)
 */
/**
 * Definition for singly-linked list.
 *  */

// eslint-disable-next-line no-unused-vars
function ListNode(val, next) {
    this.val = (val === undefined ? 0 : val)
    this.next = (next === undefined ? null : next)
}

/**
 * @param {ListNode} head
 * @return {ListNode}
 */
var reverseList = function (head) {
    let pre = null
    let nxt
    let cur = nxt = head
    while (cur != null) {
        nxt = cur.next
        cur.next = pre
        pre = cur
        cur = nxt
    }
    return pre
};

console.log(reverseList)